package com.zut.fitness.controller;


import ch.qos.logback.classic.pattern.DateConverter;
import com.zut.fitness.common.Result;
import com.zut.fitness.pojo.dto.ClassDto;
import com.zut.fitness.service.IGroupClassService;
import com.zut.fitness.pojo.GroupClass;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * 团课列表Controller
 * 
 * @author yuanML2018
 * @date 2025-01-04
 */
@RestController
@RequestMapping("/GroupClass")
public class GroupClassController
{
    @Autowired
    private IGroupClassService groupClassService;

    /**
     * 查询团课列表列表
     */

    @GetMapping("/list")
    public Result<List<GroupClass>> list(
            @RequestParam(value = "categoryId", required = false) Long categoryId,
            @RequestParam(value = "startTime", required = false) String startTimeStr
    ) throws ParseException {
        GroupClass groupClass = new GroupClass();
        if (categoryId != null) {
            groupClass.setCategoryId(categoryId);
        }
        if (startTimeStr != null && !startTimeStr.isEmpty()) {

            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");

            Date startTime = dateFormat.parse(startTimeStr);
            groupClass.setStartTime(startTime);

        }
        groupClass.setIfShow(1L);
        List<GroupClass> list = groupClassService.selectGroupClassList(groupClass);
        return Result.success(list);
    }





    @GetMapping(value = "/{id}")
    public Result<GroupClass> getInfo(@PathVariable("id") Long id)
    {
        return Result.success(groupClassService.selectGroupClassById(id));
    }

   }
